<template>
  <div class="morecirle-box">
    <scrollMore
      :showMoreTitle="false"
      :noMore="false"
    >
      <div class="morecircle">
        <div class="box" ref="box">
          <div class="topcheck f-j-sb-a-c">
            <div class="alltitle">
              <!-- {{ ids == 0 ? "全部圈子" : ids == 1 ? "我加入的" : "我创建的" }} -->
              全部圈子
            </div>

            <div class="topswtich f-a-c">
            <!-- 分类下拉选 -->
              <div class="xialabox">
                <div class="xialaboxitem f-j-a-c" @click="openwinwo">
                  {{ sortList[sortListActive].plate_name }}
                  <svg-icon name="icon-shang" class="shang"></svg-icon>
                </div>
                <div class="xialaboxlist" v-if="check">
                  <div
                    class="xialalistitem click f-j-a-c"
                    v-for="(item, index) in sortList"
                    :key="index"
                    @click="sortListClic(item,index)"
                  >
                    {{ item.plate_name }}
                  </div>
                </div>
              </div>

              <!-- 搜索栏 -->
              <!-- <div class="swtichinput f-a-c" :class="geiblur ? 'boderinput' : ''">
                <img src="../../../assets/image/icon-search@2x.png" alt="" />
                <input
                  type="text"
                  placeholder="搜索圈子"
                  @focus="huoqu"
                  @blur="geo"
                  v-model="sousuo"
                  @keydown.enter="searchinput"
                />
              </div> -->
            </div>
          </div>

          <!-- 圈子列表 -->
          <communityCircle
            :list="listbix"
            :ids="ids"
            :rowNum="5"
            :pt="20"
          ></communityCircle>

          <!-- <nodata class="f-j-a-c" v-if="!listbix.length"></nodata> -->

          <div class="moban" @click="mobanCLick" v-if="check"></div>
        </div>
      </div>
    </scrollMore>
  </div>
</template>

<script>
import nodata from "@/components/noData.vue";
import {
  Mycircle,
  nearlyAndfollows,
  byplateid,
  search,
  options,
} from "@/axios/community.js";
import { ElMessage } from "element-plus";
import { useRouter } from "vue-router";
import communityCircle from "@/components/communityCircle.vue";
import scrollMore from "@/components/scrollMore.vue";

import {
  computed,
  defineComponent,
  onMounted,
  reactive,
  toRefs,
  getCurrentInstance,
  onUnmounted,
  ref,
  watch,
} from "vue";
import { useStore } from "vuex";

export default defineComponent({
  components: {
    nodata,
    communityCircle,
    scrollMore,
  },
  setup() {
    const box = ref(null);
    const router = useRouter();
    const { proxy } = getCurrentInstance();
    let store = useStore();
    let data = reactive({
      // columnWidth: "328px", // 初始的列宽度值
      geiblur: false,
      sousuo: "",
      check: false,
      sortList: [
        {
          plate_name: "推荐",
          id: -1,
        },
        {
          plate_name: "最新",
          id: 0,
        },
      ], //分类
      sortListActive:0, //分类选中下标
      listbix: [], //圈子列表
    });
    onMounted(() => {
      getoptions();
      getbyplateid();
    });


    //搜索
    // let searchinput = (e) => {
    //   console.log(e.target.value);
    //   data.listbix = [];
    //   let id = "?keyword=" + e.target.value;
    //   search({ id }).then((res) => {
    //     let datalist = res.data.data;
    //     datalist.forEach((item, index) => {
    //       data.listbix.push(item);
    //     });
    //   });
    // };

    // 获取列表
    let getbyplateid = () => {  
      let id = "?plate_id=" + data.sortList[data.sortListActive].id;
      data.listbix = [];
      byplateid({ id }).then((res) => {
        data.listbix = res.data;
      });
    };


    //失去
    let geo = () => {
      data.geiblur = false;
    };
    // 获取焦点
    let huoqu = () => {
      data.geiblur = true;
    };


    // 分类点击
    let sortListClic = (item,index) => {
      data.check = false;
      if(data.sortListActive == index) return
      data.sortListActive = index;
      getbyplateid();
    };


    // 打开
    let openwinwo = () => {
      data.check = !data.check;
    };

    // 模板点击
    let mobanCLick = () => {
      data.check = false;
    };



    // 获取圈子分类
    let getoptions = () => {
      options().then((res) => {
        data.sortList = [...data.sortList, ...res.data];
      });
    };



    return {
      // searchinput,
      box,
      getbyplateid,
      geo,
      huoqu,
      mobanCLick,
      sortListClic,
      openwinwo,
      getoptions,
      // observer,
      // handleScroll,
      ...toRefs(data),
    };
  },
});
</script>
<style lang="scss" scoped>
.morecirle-box {
  background: #f9f9f9;
  height: 100%;
}

.boderinput {
  border: 1px solid #64c8dc !important;
}
.swtichinput {
  position: relative;
  width: 200px;
  height: 40px;
  border-radius: 10px 10px 10px 10px;
  opacity: 1;
  border: 1px solid #ececec;
  margin-left: 10px;

  > img {
    position: absolute;
    left: 10px;
    width: 13px;
    height: 13px;
  }
  > input {
    background: #f9f9f9;
    padding: 0 25px;
    border: none;
    width: 100%;
    height: 100%;
    border-radius: 10px;
  }
}
.topcheck {
  width: 100%;
  padding-top: 20px;
  .xialabox {
    position: relative;
    cursor: pointer;
    .xialaboxitem {
      transition: 0.2s;
      width: 156px;
      height: 40px;
      border-radius: 10px 10px 10px 10px;
      border: 1px solid #ececec;
      font-size: 14px;
      font-family: Microsoft YaHei-Regular, Microsoft YaHei;
      font-weight: 400;
      color: #656f79;
      .shang {
        margin-left: 5px;
        transform: rotate(180deg);
      }
      &:hover {
        border: 1px solid #64c8dc;
      }
    }
    .xialaboxlist {
      position: absolute;
      z-index: 2;
      top: 50px;
      width: 156px;
      height: 400px;
      background: #ffffff;
      box-shadow: 0px 0px 15px 0px rgba(0, 0, 0, 0.1);
      border-radius: 10px 10px 10px 10px;
      opacity: 1;
      overflow: auto;
      font-size: 14px;
      font-family: Microsoft YaHei-Regular, Microsoft YaHei;
      font-weight: 400;
      color: #000000;
      .xialalistitem {
        height: 40px;
        width: 100%;
        background-color: #fff;
        &:hover {
          background-color: rgba(100, 200, 220, 0.3);
          font-size: 14px;
          font-family: Microsoft YaHei-Regular, Microsoft YaHei;
          font-weight: 400;
          color: #64c8dc;
        }
      }
    }
  }
}
.alltitle {
  // margin-top: 31px;

  font-size: 20px;
  font-family: Microsoft YaHei-Bold, Microsoft YaHei;
  font-weight: 700;
  color: #000000;
  line-height: 20px;
}
.chekc {
  margin-top: 24px;
  .item {
    > span {
      font-size: 14px;
      font-family: Microsoft YaHei-Regular, Microsoft YaHei;
      font-weight: 400;
      color: #656f79;
    }
    &:last-child {
      margin-left: 40px;
    }
  }
  .itemactive {
    color: #64c8dc !important;
  }
}

.morecircle {
  // padding: 0 14%;
  // position: absolute;
  // top: 80px;
  // min-height: 100vh;
  // padding-bottom: 50px;
  // height: 100vh;
  // overflow: auto;
  // background: #f9f9f9;
  padding: 0 30px;
  max-width: 1440px;
  // min-width: 1200px;
  margin: 0 auto;
}

.xialaboxlist::-webkit-scrollbar {
  width: 3px;
  height: 3px;
}
/* 滚动条滑块样式 */
.xialaboxlist::-webkit-scrollbar-thumb {
  background-color: #ececec;
  border-radius: 2px;
}

/* 滚动条轨道样式 */
.xialaboxlist::-webkit-scrollbar-track {
  background-color: #f7f9fa;
  height: 80% !important;
}

/* 鼠标悬停时滚动条轨道样式 */
.xialaboxlist::-webkit-scrollbar-track:hover {
  background-color: #f7f9fa;
}
.moban {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}
</style>
